# coding: utf-8
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

# 设置随机数种子，确保每次运行代码时生成的随机数相同
np.random.seed(1)
# 1000 random integers between 0 and 50
# 生成50个0到99之间的随机整数
x = np.random.randint(0, 100, 50)
# Positive Correlation with some noise  # 正相关关系，带有一些噪声（但在这行代码中噪声被注释掉了）
# y1 = 0.8*x + np.random.normal(0, 15, 50)
y1 = 0.8*x
# Negative Correlation with some noise
y2 = 100 - 0.7*x + np.random.normal(0, 15, 50)
# No/Weak Correlatio
y3 = np.random.randint(0, 100, 50)

# 计算x和y1之间的相关系数矩阵
r1=np.corrcoef(x, y1)
r2=np.corrcoef(x, y2)
r3=np.corrcoef(x, y3)
fig = plt.figure()

plt.subplot(131)
plt.scatter(x, y1,color='k')        # 第一个子图，展示x和y1的散点图  # 'k'代表黑色
plt.subplot(132)
plt.scatter(x, y2,color='k')
plt.subplot(133)
plt.scatter(x, y3,color='k')
print (r1)
print (r2)
print (r3)
plt.show()
# fig.savefig('./img/correlation1.png',dpi=600)